package models;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;

import models.RegisteredUser;
import play.db.jpa.*;

@Entity
/***@author dana
 * This is the ReviewRequest class having the attributes: name,requesterID,reviewerID and ExId 
 *
 */
public class ReviewRequest extends Model {

	public String name;
	public long requesterID;
	public long reviewerID;
	public long ExId;
	public boolean isChecked;

	@ManyToMany(mappedBy = "listOfReviewRequest", cascade = CascadeType.ALL)
	public List<RegisteredUser> reviewersList;

	/***
	 * @author dana The constructor
	 * @param requesterID
	 * @param reviewerID
	 * @param name
	 * @param ExId
	 */
	public ReviewRequest(long requesterID, long reviewerID, String name,
			long ExId) {

		this.requesterID = requesterID;
		this.reviewerID = reviewerID;
		this.name = name;
		this.ExId = ExId;
		this.reviewersList = new ArrayList();
		this.isChecked = false;
		this.save();

	}

	public boolean isChecked() {
		return isChecked;
	}

	public void setChecked(boolean isChecked) {
		this.isChecked = isChecked;
	}

	/***
	 * @author dana This method prints a message to the reviewer
	 */
	public String toString() {

		String s = "";
		
		try {

			RegisteredUser user = RegisteredUser.findById(this.requesterID);
			Exercise x = Exercise.findById(this.ExId);

			s = "" + "" + user.name + " has sent you a review request"
					+ " to review the exercise having the name "
					+ x.getExerciseName();
			
		} catch (NullPointerException e) {

			s = "Oopss...a null pointer exception was found :ssss";
		}
		return s;
	}
}